<template>
    <div>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>用户名</td>
                    <td><input type="text" v-model="querinfo.username"></td>
                </tr>
                <tr>
                    <td>密码</td>
                    <td><input type="password" v-model="querinfo.userpwd"></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="登录" @click="ok"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref, reactive, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useStore } from '@/stores/user'
const a = useStore();
const route = useRoute();
const router = useRouter();

let querinfo: any = reactive({
    username: '',
    userpwd: ''
})
const ok = () => {
    if (querinfo.username == "") {
        alert("用户名不能为空");
        return;
    }
    if (querinfo.userpwd == "") {
        alert("密码不能为空");
        return;
    }
    axios({
        url: '/api/Admin/Login',
        method: 'post',
        params: querinfo
    })
        .then(res => {
            if (res.data == -1) {
                alert("用户名错误");
                return;
            }
            else if (res.data == -2) {
                alert("密码错误");
                return;
            } else {
                alert("登录成功");
                a.userinfo = res.data
                router.push("/adminList")
                return;
            }
        })
}



</script>

<style scoped></style>